package com.example.ykbboom.universitytransportation.Activity;

import android.app.ProgressDialog;
import android.content.SharedPreferences;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.ykbboom.universitytransportation.R;
import com.example.ykbboom.universitytransportation.Util.NetUtil;
import com.example.ykbboom.universitytransportation.Util.SharedPrefUtil;
import com.example.ykbboom.universitytransportation.Util.ToastUtil;

public class UserReportActivity extends BaseActivity {

    private Toolbar mToolbar;
    private Button submitReportBtn;
    private EditText reportText;
    private ProgressDialog progressDialog;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_report);
        initView();
    }
    @Override
    public void initView() {
        super.initView();
        mToolbar = (Toolbar) findViewById(R.id.toolbar_user_report);
        setSupportActionBar(mToolbar);
        ActionBar actionBar = getSupportActionBar();
        if(actionBar!=null){
            actionBar.setHomeButtonEnabled(true); //设置返回键可用
            actionBar.setDisplayHomeAsUpEnabled(true);//显示HomeAsUp按钮
            actionBar.setDisplayShowTitleEnabled(false);//不自动显示标题
        }
        submitReportBtn = (Button) findViewById(R.id.submit_report);
        submitReportBtn.setOnClickListener(this);
        reportText = (EditText) findViewById(R.id.report_desc_text);
        progressDialog = new ProgressDialog(this);
    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item){
        switch (item.getItemId()){
            case android.R.id.home:
                finish();
        }
        return true;
    }

    public void showDialog() {
        progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        progressDialog.setIndeterminate(false);
        progressDialog.setCancelable(false);
        progressDialog.setMessage("正在提交反馈...");
        progressDialog.show();
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()){
            case R.id.submit_report:
                if (reportText.getText().toString()==null||reportText.getText().toString().trim().equals("")){
                    ToastUtil.showToast(this,"请输入投诉内容。");
                    break;
                }
                showDialog();
                NetUtil.userReport(reportText.getText().toString(),SharedPrefUtil.getUserPhone(),progressDialog);
                break;
        }
    }
}
